package com.rabbit.config;

import com.rabbit.interceptor.CorsInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <h1>拦截器相关配置</h1>
 *
 * @author zjw
 * @date 2021/6/29 15:29
 */
public abstract class AbstractWebMvcConfig implements WebMvcConfigurer {

    @Value("${allowOrigin}")
    private String allowOrigin;

    @Bean
    public MethodValidationPostProcessor methodValidationPostProcessor() {
        return new MethodValidationPostProcessor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CorsInterceptor(allowOrigin));
        addCustomInterceptors(registry);
    }

    /**
     * 添加其它的拦截器
     */
    protected abstract void addCustomInterceptors(InterceptorRegistry registry);
}
